/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package 解析.node.node;

import 解析.node.others.TreeInfo;
import 解析.Matcher;

/**
 *
 * @author yanxi
 */
public class Start extends Node { 
    public int minLength;

    public Start(Node node) {
        this.next = node;
        TreeInfo info = new TreeInfo();
        next.study(info);
        minLength = info.minLength; 
    }
    
    @Override
    public boolean match(Matcher matcher, int i, CharSequence seq) {
        if (i > matcher.to - minLength) {
            matcher.hitEnd = true;
            return false;
        }
        int guard = matcher.to - minLength;
        for (; i <= guard; i++) {
            if (next.match(matcher, i, seq)) {
                matcher.first = i;
                matcher.groups[0] = matcher.first;
                matcher.groups[1] = matcher.last;
                return true;
            }
        }
        matcher.hitEnd = true;
        return false;
    }

    @Override
    public boolean study(TreeInfo info) {
        next.study(info);
        info.maxValid = false;
        info.deterministic = false;
        return false;
    } 
    @Override
    public String toString(){
        //return "["+this.getClass().getName()+"]"+"minLength:"+minLength;
        return "<<开始>>";
    }
}
